package com.y.fund.utils;

public class TempStr {

	private final static String hexDigits = "0123456789ABCDEF";

    public static boolean isBlank(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if ((!Character.isWhitespace(str.charAt(i)))) {
                return false;
            }
        }
        return true;
    }

    public static String bytes2HexStr(byte[] b) {
        String stmp="";  
        StringBuilder sb = new StringBuilder();  
        for (int n=0;n<b.length;n++){  
            stmp = Integer.toHexString(b[n] & 0xFF);  
            if(stmp.length() < 2){
                sb.append("0");
            }
            sb.append(stmp);
        }  
        return sb.toString().toUpperCase();  
    }
    
    /** Convert hexadecimal string to binary */
    public static byte[] hex2Bytes(String hexStr) {
        if (isBlank(hexStr)){
        	return null;
        }
          
        char[] hexs = hexStr.toUpperCase().toCharArray();    
        byte[] bytes = new byte[hexStr.length() / 2];    
        int n;    

        for (int i = 0; i < bytes.length; i++)  
        {    
            n = hexDigits.indexOf(hexs[2 * i]) * 16;    
            n += hexDigits.indexOf(hexs[2 * i + 1]);    
            bytes[i] = (byte) (n & 0xff);    
        }    
        return bytes;    
    }
    
}
